package com.along.textdemo.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileUtils {

    public static final String DATA_DIRECTORY = Environment
            .getExternalStorageDirectory() + "/audios_my_recorder";

    /**
     * 音频保存路径
     * @param context
     * @return
     */
    public static String audioSavePath(Context context) {
        return DATA_DIRECTORY;
    }

    /**
     * 创建音频文件
     * @param suffix
     * @return
     */
    public static String createAudioPath(String suffix) {
        return DATA_DIRECTORY + "AUD_" + new SimpleDateFormat("HH_mm_ss").format(new Date()) + "." + suffix;
    }

    /**
     * 创建不同的目录
     */
    public static void createDirectory() {
        if (sdCardExists()) {
            File file = new File(DATA_DIRECTORY);
            if (!file.exists()) {
                file.mkdirs();
            }
        } else {
            File file = new File(DATA_DIRECTORY);
            if (!file.exists()) {
                file.mkdirs();
            }
        }
    }

    public static boolean sdCardExists() {
        return Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED);
    }
}
